import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _uniqBy from "lodash/uniqBy";
import _isEmpty from "lodash/isEmpty";

var _dec, _class;

import React, { PureComponent } from 'react';
import { Table, Popconfirm, Tag } from 'antd';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { enableRender, operatorRender } from 'utils/renderer';
import { tableScrollWidth, getCurrentOrganizationId } from 'utils/utils';
import { VERSION_IS_OP } from 'utils/config';
import { Bind } from 'lodash-decorators';
/**
 * 发送配置数据展示列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onSearch - 分页查询
 * @reactProps {Boolean} loading - 数据加载完成标记
 * @reactProps {Array} dataSource - Table数据源
 * @reactProps {Object} pagination - 分页器
 * @reactProps {Number} pagination.current - 当前页码
 * @reactProps {Number} pagination.pageSize - 分页大小
 * @reactProps {Number} pagination.total - 数据总量
 * @return React.element
 */

var ListTable = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ListTable, _PureComponent);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "editOption",
    value:
    /**
     * 编辑
     * @param {object} record - 数据对象
     */
    function editOption(record) {
      this.props.onEdit(record);
    }
  }, {
    key: "handleCopy",
    value: function handleCopy(record) {
      var onCopy = this.props.onCopy;
      onCopy(record);
    }
    /**
     * 删除
     * @param {object} record - 数据对象
     */

  }, {
    key: "deleteOption",
    value: function deleteOption(record) {
      this.props.onDelete(record);
    }
    /**
     * 发送
     *
     * @memberof ListTable
     */

  }, {
    key: "sendOption",
    value: function sendOption(record) {
      this.props.onOpenSendModal(record);
    }
    /**
     * 渲染启用服务
     * @param {*} item
     */

  }, {
    key: "typeMeaningRender",
    value: function typeMeaningRender(item) {
      var mean = '';

      switch (item.typeCode) {
        case 'WEB':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "green",
            key: "1"
          }, item.typeMeaning);
          break;

        case 'EMAIL':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "orange",
            key: "2"
          }, item.typeMeaning);
          break;

        case 'SMS':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "blue",
            key: "3"
          }, item.typeMeaning);
          break;

        case 'WC_E':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "red",
            key: "4"
          }, item.typeMeaning);
          break;

        case 'WC_O':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "#9866ff",
            key: "5"
          }, item.typeMeaning);
          break;

        case 'DT':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "pink",
            key: "6"
          }, item.typeMeaning);
          break;

        case 'CALL':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "#00ccff",
            key: "7"
          }, item.typeMeaning);
          break;

        case 'WEB_HOOK':
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "rgb(187, 103, 222)",
            key: "7"
          }, item.typeMeaning);
          break;

        default:
          mean = /*#__PURE__*/React.createElement(Tag, {
            color: "#dcdcdc",
            key: "6"
          }, item);
          break;
      }

      return mean;
    }
    /**
     * render
     * @returns React.element
     */

  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          loading = _this$props.loading,
          dataSource = _this$props.dataSource,
          pagination = _this$props.pagination,
          _onChange = _this$props.onChange,
          tenantRoleLevel = _this$props.tenantRoleLevel,
          path = _this$props.path;
      var columns = [!tenantRoleLevel && {
        title: intl.get('entity.tenant.tag').d('租户'),
        dataIndex: 'tenantName',
        width: 150
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.messageCode').d('消息代码'),
        dataIndex: 'messageCode',
        width: 200
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.messageName').d('消息名称'),
        dataIndex: 'messageName'
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.typeMeaning').d('启用服务'),
        dataIndex: 'typeMeaning',
        width: 420,
        render: function render(val, record) {
          var types = [];

          if (!_isEmpty(record.serverList)) {
            var list = record.serverList.map(function (item) {
              return {
                typeCode: item.typeCode,
                typeMeaning: item.typeMeaning
              };
            });
            types = _uniqBy(list, 'typeCode');
          }

          return /*#__PURE__*/React.createElement("span", null, types && types.map(function (item) {
            return _this.typeMeaningRender(item);
          }));
        }
      }, // {
      //   title: intl.get('cmsg.sendConfig.model.sendConfig.receiveConfigCode').d('接收配置编码'),
      //   dataIndex: 'receiveCode',
      //   width: 120,
      // },
      tenantRoleLevel && !VERSION_IS_OP && {
        title: intl.get('cmsg.common.view.source').d('来源'),
        width: 120,
        dataIndex: 'tenantId',
        render: function render(_, record) {
          var tenantId = getCurrentOrganizationId();
          return tenantId.toString() === record.tenantId.toString() ? /*#__PURE__*/React.createElement(Tag, {
            color: "green"
          }, intl.get('cpaas.common.custom').d('自定义')) : /*#__PURE__*/React.createElement(Tag, {
            color: "orange"
          }, intl.get('cpaas.common.predefined').d('预定义'));
        }
      }, {
        title: intl.get('cpaas.common.status').d('状态'),
        dataIndex: 'enabledFlag',
        width: 100,
        render: enableRender
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        dataIndex: 'operator',
        width: 200,
        fixed: 'right',
        render: function render(val, record) {
          var operators = [];
          var tenantId = getCurrentOrganizationId();

          if (!tenantRoleLevel || tenantId.toString() === record.tenantId.toString()) {
            operators.push({
              key: 'edit',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.edit"),
                  type: 'button',
                  meaning: '消息发送配置-编辑'
                }],
                onClick: function onClick() {
                  return _this.editOption(record);
                }
              }, intl.get('cpaas.common.button.edit').d('编辑')),
              len: 2,
              title: intl.get('cpaas.common.button.edit').d('编辑')
            }, {
              key: 'delete',
              ele: /*#__PURE__*/React.createElement(Popconfirm, {
                placement: "topRight",
                title: intl.get('cpaas.common.message.confirm.delete').d('是否删除此条记录？'),
                onConfirm: function onConfirm() {
                  return _this.deleteOption(record);
                }
              }, /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.delete"),
                  type: 'button',
                  meaning: '消息发送配置-删除'
                }]
              }, intl.get('cpaas.common.button.delete').d('删除'))),
              len: 2,
              title: intl.get('cpaas.common.button.delete').d('删除')
            });

            if (record.enabledFlag && record.serverList && record.serverList.length !== 0) {
              operators.push({
                key: 'testSend',
                ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                  type: "text",
                  permissionList: [{
                    code: "".concat(path, ".button.testSend"),
                    type: 'button',
                    meaning: '消息发送配置-测试发送'
                  }],
                  onClick: function onClick() {
                    return _this.sendOption(record);
                  }
                }, intl.get('cmsg.sendConfig.view.title.testSend').d('测试发送')),
                len: 4,
                title: intl.get('cmsg.sendConfig.view.title.testSend').d('测试发送')
              });
            }
          }

          if (tenantId.toString() !== record.tenantId.toString() && tenantRoleLevel && !VERSION_IS_OP) {
            operators.push({
              key: 'copy',
              ele: /*#__PURE__*/React.createElement("a", {
                onClick: function onClick() {
                  return _this.handleCopy(record);
                }
              }, intl.get('cpaas.common.button.copy').d('复制')),
              len: 2,
              title: intl.get('cpaas.common.button.copy').d('复制')
            });
          }

          return operatorRender(operators);
        }
      }].filter(Boolean);
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "tempServerId",
        loading: loading,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        dataSource: dataSource,
        pagination: pagination,
        onChange: function onChange(page) {
          return _onChange(page);
        }
      });
    }
  }]);

  return ListTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleCopy", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleCopy"), _class.prototype)), _class));
export { ListTable as default };